﻿/**
* @file 单轴参数设置
* @brief
*
*
*
* @author
* @date
* @see
* @note
*
*
*
*/
#include "handshakewidget.h"

QHandShakeWidget::QHandShakeWidget(int i32AxisNo,QString sAxisName,QWidget *parent) : QWidget(parent)
{
    _i32AxisNo = i32AxisNo;
    _sAxisName = sAxisName;
    _i32FrameCnt = 0;

    InitUI();

    QString sInfo;
    sInfo = QString("当前位置:%1\n当前速度:%2\n").arg(0).arg(0);
    _pShowInfoLabel->setText(sInfo);


    connect(_pSetParamButton,&QPushButton::clicked,this,&QHandShakeWidget::onSetParamButtonClick);
    connect(_pStopButton,&QPushButton::clicked,this,&QHandShakeWidget::onStopBtnClick);



}

QHandShakeWidget::~QHandShakeWidget()
{

}
/**
* @brief 初始化界面
* @note
*
*/
void QHandShakeWidget::InitUI()
{
    this->setStyleSheet("QLabel{font-family: 'Microsoft YaHei';}");

    QLabel* plabel = new QLabel(_sAxisName);
    plabel->setStyleSheet("QLabel{color:rgb(0,0,255);font-size:20px;font-family: 'Microsoft YaHei';}");


    _pValueEdit = new QLineEdit("0.0",this);
    _pValueEdit->setMinimumHeight(25);
    QUIQss::setTxtQss(_pValueEdit, "#DCE4EC", "#1ABC9C");

    _pSetParamButton = new QPushButton("握手",this);
    QUIQss::setBtnQss(_pSetParamButton,"#1ABC9C", "#E6F8F5", "#2EE1C1", "#FFFFFF", "#16A086", "#A7EEE6");

    _pStopButton = new QPushButton("停止",this);


    _pShowInfoLabel = new QLabel(this);
    _pShowInfoLabel->setStyleSheet("color:rgb(0,0,255);font-size:20px;font-family: 'Microsoft YaHei';");

    int nRow = 0;

    QGridLayout* playout = new QGridLayout(this);

    playout->addWidget(plabel,nRow,0,1,1);
    nRow++;
    playout->addWidget(new QLabel("模式:"),nRow,0,1,1);
    playout->addWidget(new QLabel("位置给定"),nRow,1,1,2);
    nRow++;
    playout->addWidget(new QLabel("目标转角(°):"),nRow,0,1,1);
    playout->addWidget(_pValueEdit,nRow,1,1,3);
    nRow++;
    playout->addWidget(_pSetParamButton,nRow,1,1,1);
    playout->addWidget(_pStopButton,nRow,2,1,1);
    nRow++;
    playout->addWidget(_pShowInfoLabel,nRow,0,1,4);
}

/**
* @brief 设置参数
* @note
*
*/
void QHandShakeWidget::onSetParamButtonClick()
{
    float lfValue = _pValueEdit->text().toFloat();

    int i32value = lfValue * (16777216/360);


    emit signal_sethandshake(_i32AxisNo,i32value,3);
}

void QHandShakeWidget::onStopBtnClick()
{
    emit signal_startTest(_i32AxisNo,0x8d,0,0);

}

/**
* @brief
*
**/
void QHandShakeWidget::rcvFrameData(st_rcvdata rcvdata)
{
    _rcv_capdata = rcvdata;
    _i32FrameCnt++;
    if(_i32FrameCnt%5 != 0)
    {
        return;
    }

    if(_i32AxisNo == 0x0)//方位轴
    {
        //位置 反馈值
        fourchar l_data;
        l_data.data[3] = 0;
        l_data.data[2] = _rcv_capdata.azimuthresponse_value[0];
        l_data.data[1] = _rcv_capdata.azimuthresponse_value[1];
        l_data.data[0] = _rcv_capdata.azimuthresponse_value[2];
        _lfPosdata = l_data.ui32data*360.0/16777216;
        //速度
        if(_rcv_capdata.loopcmd == 0x11)
        {
            //方位轴
            twochar l_data;
            l_data.data[0] = _rcv_capdata.loopcmd_data.loopdata_11.azimuth_speed_response_value.data[1];
            l_data.data[1] = _rcv_capdata.loopcmd_data.loopdata_11.azimuth_speed_response_value.data[0];
            _lfSpeeddata = l_data.i16data /1000.0;
        }
    }

    if(_i32AxisNo == 0x01)//俯仰
    {
        //位置 反馈值
        fourchar l_data;
        l_data.data[3] = 0;
        l_data.data[2] = _rcv_capdata.pitchresponse_value[0];
        l_data.data[1] = _rcv_capdata.pitchresponse_value[1];
        l_data.data[0] = _rcv_capdata.pitchresponse_value[2];
        _lfPosdata = l_data.ui32data*360.0/16777216;
        //速度
        if(_rcv_capdata.loopcmd == 0x11)
        {
            twochar l_data;
            l_data.data[0] = _rcv_capdata.loopcmd_data.loopdata_11.pitch_speed_response_value.data[1];
            l_data.data[1] = _rcv_capdata.loopcmd_data.loopdata_11.pitch_speed_response_value.data[0];
            _lfSpeeddata = l_data.i16data /1000.0;
        }
    }

    //显示
    QString sInfo;
    sInfo = QString("当前位置:%1\n当前速度:%2\n").arg(_lfPosdata).arg(_lfSpeeddata);
    _pShowInfoLabel->setText(sInfo);
}
